﻿using System.Text.RegularExpressions;

namespace RegularExpressionsTest;

public class Program
{
    public static void Main(string[] args)
    {

        const string input = "hello. ";
        const string input2 = "hello ";
        const string pattern = @"([\s.])";
        var match = Regex.Matches(input, pattern);
        Console.WriteLine(match.Count);
        foreach (Match match1 in match)
        {
            Console.WriteLine($"index {match1.Index} Lenght {match1.Length} " +
                              $"Value {match1.Value} ValueSpan {match1.ValueSpan}");
        }
    }

    public static void Test1()
    {
        const string input2 = "hello dfds ";
        const string pattern = @"((\w+)[\s.])+";
        // const string pattern = @"(\w+)";
        var match = Regex.Matches(input2, pattern);
        Console.WriteLine(match.Count);
        foreach (Match match1 in match)
        {
            Console.WriteLine($"index {match1.Index} Lenght {match1.Length} " +
                              $"Value {match1.Value} ValueSpan {match1.ValueSpan}");
        }
    }

    public static void Test2()
    {
        const string input = "Yes. This dog is very friendly.sdfsd.";
        const string pattern = @"((\w+)[\s.])+";
        foreach (Match match in Regex.Matches(input, pattern))
        {
            Console.WriteLine("Match: {0}", match.Value);
            for (var groupCtr = 0; groupCtr < match.Groups.Count; groupCtr++)
            {
                Group group = match.Groups[groupCtr];
                Console.WriteLine(" Group {0}: {1}", groupCtr, group.Value);
                for (var captureCtr = 0; captureCtr < group.Captures.Count;
                     captureCtr++)
                    Console.WriteLine(" Capture {0}: {1}", captureCtr,
                        group.Captures[captureCtr].Value);
            }
        }
    }

    public static void Test3()
    {
        // var pattern = @"([a-z]+)(\d+)?\.([a-z]+(\d)*)";
        var pattern = @"^([a-z]+)(\d+)?\.([a-z]+(\d)*)$";
        string[] values = { "AC10.f4333", "Za203.CYM", "XYZ.CoA", "ABC.x170h" };
        foreach (var value in values)
        {
            Console.WriteLine("Count "+Regex.Matches(value, pattern, RegexOptions.IgnoreCase).Count);
            Match match1 = Regex.Matches(value, pattern, RegexOptions.IgnoreCase)[0];
            Console.WriteLine($"index {match1.Index} Lenght {match1.Length} " +
                              $"Value {match1.Value} ValueSpan {match1.ValueSpan}");
            Console.WriteLine("0: "+match1.Groups[0]+" \n1: "+match1.Groups[1]);
            Console.WriteLine("2: "+match1.Groups[2]+" \n3: "+match1.Groups[3]);
            Console.WriteLine("4: "+match1.Groups[4]);
            Console.WriteLine("Group "+match1.Groups.Count+"\n");

            foreach (Capture c in match1.Groups[4].Captures)
            {
                Console.WriteLine(c);
            }


        }
    }
}